<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/tld/taglib.tld" prefix="p" %>
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <jsp:include page="/public/inc/head.jsp"/>
</head>
<body>
<div id="header" class="navbar navbar-static-top" role="navigation">
    <jsp:include page="/public/inc/top.jsp"/>
</div>
<div class="container-fluid" style="margin-top:5px;margin-bottom:60px;">
    <div class="row">
        <jsp:include page="/public/inc/menu.jsp"/>
        <div class="col-xs-12 col-sm-10">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <div class="media">
                        <div class="media-body">
                            <span class="glyphicon glyphicon-list"></span>分销产品统计
                        </div>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="form-inline">
                        <form id="form1" action="/system/wwdx_merchant_product_statistics/list">
                            <div class="form-group">
                                <div class="col-lg-6">
                                    <label>
                                        <select id="merchant_id" name="merchant_id" class="form-control">
                                            <option value="">选择商户</option>
                                        </select>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-lg-6">
                                    <label>
                                        <select id="product_id" name="product_id" class="form-control">
                                            <option value="">选择产品</option>
                                        </select>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-offset-2 col-md-10">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fa fa-search"></i> 筛选
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>时间</th>
                            <th>点击PV</th>
                            <th>点击UV</th>
                            <th>订单人数</th>
                            <th>分成比例</th>
                            <th>产品单价</th>
                            <th>订单收益</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="l" items="${list}" varStatus="status">
                            <tr>
                                <td>
                                        ${status.index+1}
                                </td>
                                <td>
                                        ${l.date}
                                </td>
                                <td>
                                        ${l.pvCount}
                                </td>
                                <td>
                                        ${l.uvCount}
                                </td>
                                <td>
                                        ${l.userCount}
                                </td>
                                <td>
                                        ${l.scale}%
                                </td>
                                <td>
                                    ￥${l.price}
                                </td>
                                <td>
                                    ￥${l.priceCount}
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
                <div class="panel-footer">
                    <p:pagination url="/system/wwdx_merchant_product_statistics/list" total="${listSize}"/>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<jsp:include page="/public/inc/bottom.jsp"/>
</html>
<script type="text/javascript">
    
    var merchantId;
    
    function initProductList(merchantId) {
        //清除所有option值
        $("#product_id").empty();
        var productId = document.getElementById("product_id");
        productId[0] = new Option("选择产品", "",true);
        $.ajax({
            url: "/system/wwdx_merchant_product/list/json",
            data:{merchant_id:merchantId},
            dataType: "json",
            success: function (data) {
                $.each(data.data, function (index, obj) {
                    //item.options.length = 0;清除所有option值
                    obj = productId[index + 1] = new Option(obj.productName, obj.productId);
                    if (obj.value === '${model.product_id}') {
                        obj.selected = "selected";
                    }
                });
            },
            error: function (data) {
                alert(data.message);
            }
        });
    }
    
    merchantId = '${model.merchant_id}';
    initProductList(merchantId);
    $(function () {
        /**
         * 商户列表
         */
        $.ajax({
            url: "/system/wwdx_merchant/list/json",
            dataType: "json",
            success: function (data) {
                merchantId = document.getElementById("merchant_id");
                $.each(data.data, function (index, obj) {
                    //item.options.length = 0;清除所有option值
                    obj = merchantId[index + 1] = new Option(obj.merchant_name, obj.id);
                    if (obj.value === '${model.merchant_id}') {
                        obj.selected = "selected";
                    }
                });
            },
            error: function (data) {
                alert(data.message);
            }
        });

        /**
         * 商户产品列表
         */
        $("#merchant_id").change(function(){
            merchantId = $("#merchant_id").val();
            initProductList(merchantId);
        });

        $("#form1").bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                merchant_id: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        }
                    }
                }, 
                product_id: {
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        }
                    }
                }
            }
        });
    });
</script> 